<style>
/*.layui-form-pane .layui-form-label{width:auto;}
.layui-form-item{margin-bottom: 0px;}
.order-time-bg{background-color:#1E9FFF;color:white;padding:0px 5px;}*/
</style>
<div class="page-toolbar">
    <div class=" fixed-bar">
        <form class="layui-form layui-form-pane fixed-bar-form" action="{:url()}" method="get" id="hisi-table-search">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">搜索子工厂/组别名称关键词</label>
                <div class="layui-input-inline">
                    <input type="text" name="keyword"  placeholder="输入关键字，按回车搜索" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">所属父工厂名称</label>
                <div class="layui-input-inline">
                  {:Form::select('factory_id', '', $factoryKV, '', '')}
                </div>
            </div>
            <div class="layui-inline">
                <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">搜索</button>
            </div>
        </div>
        
    </div>
</div>

<table id="dataTable"></table>

{include file="system@block/layui" /}

<script type="text/html" title="操作按钮模板" id="buttonTpl">
    <a href="{:url('edit')}?id={{ d.id }}" class="layui-btn layui-btn-xs layui-btn-normal hisi-iframe" hisi-data="{width: '470px', height: '600px'}" title="修改组别">修改</a>
	<a href="{:url('status?val=0')}?id={{ d.id }}" class="layui-btn layui-btn-xs layui-btn-danger j-tr-del">删除</a>
</script>

<script type="text/html" title="排序模板" id="sortTpl">
    <input type="text" class="layui-input hisi-ajax-input input-sort" onkeyup="value=value.replace(/[^\d]/g,'')" value="{{ d.order }}" data-value="{{ d.id }}" data-href="{:url('sort')}?id={{ d.id }}&field=order">
</script>

<script type="text/html" id="toolbar">
    <div class="layui-btn-group fl">
        <a href="{:url('add')}" class="layui-btn layui-btn-primary layui-btn-sm layui-icon layui-icon-add-circle-fine hisi-iframe" hisi-data="{width: '470px', height: '600px'}" title="添加组别">&nbsp;添加</a>
		<a data-href="{:url('status?val=0')}" class="layui-btn layui-btn-primary layui-btn-sm j-page-btns confirm layui-icon layui-icon-close red">&nbsp;删除</a>
    </div>
</script>
<script type="text/html" id="updateTimeTpl">
    <div>{{layui.util.toDateString(d.update_time * 1000) }}</div>
</script>
<script type="text/html" id="unit_set_flagTpl">
    <input type="checkbox" name="switch" lay-filter="switch_unit_set_flag" data-option="{{d.id}}" lay-skin="switch"
           {{# if(d.unit_set_flag == 0){ }}
           checked
           {{# } }}
    >
</script>
<script src="__PUBLIC_JS__/jquery.2.1.4.min.js?v={:config('hisiphp.version')}"></script>
<script src="__PUBLIC_JS__/xm-select/dist/xm-select.js?v={:config('hisiphp.version')}"></script>
<script src="__PUBLIC_JS__/vue@3.2.26/dist/vue.global.js"></script>
<script type="text/javascript">
    layui.use(['table', 'tool', 'form'], function() {
        var table = layui.table;
        var form = layui.form;
        table.render({
            elem: '#dataTable'
            ,url: '{:url()}' //数据接口
            ,page: true //开启分页
            ,skin: 'row'
            ,even: true
            ,limit: 20
            ,limits: [20,50,100,150,200]
            ,text: {
                none : '暂无相关数据'
            }
            ,toolbar: '#toolbar'
            ,defaultToolbar: ['filter', 'exports', 'print']
            ,cols: [[ //表头
                {type:'checkbox', fixed:'left'}
                ,{field: 'id', title: '编号', sort: true}
                ,{field: 'factory_name', title: '父工厂名称'}
                ,{field: 'name', title: '子工厂/组别名称'}
                ,{field: 'unit_cutting', title: '裁床倍率(MSE加工费)'}
                ,{field: 'unit_workshop', title: '车间倍率(MSE加工费)'}
                ,{field: 'unit_tail', title: '尾部倍率(MSE加工费)'}
                ,{field: 'unti_manual', title: '专机或手工倍率(MSE加工费)'}
                ,{field: 'unit_time_price', title: '计时工价(元/时)'}
                ,{field: 'out_type_txt', title: '委外类型'}
                ,{field: 'update_time', title: '更新时间',templet: '#updateTimeTpl'}
                ,{field: 'order', title: '排序', templet: '#sortTpl'}
                ,{field: 'unit_set_flag', title: '自动审核',templet: '#unit_set_flagTpl'}
                ,{title: '操作', templet: '#buttonTpl', fixed: 'right'}
            ]]
        });

        //监听开关 点击触发事件
        form.on('switch(switch_unit_set_flag)', function(data){
            //switch(switchTest)
            //开关的是switch，普通的多选框是checkbox；
            //括号内是lay-filter，每一个checbox中都要有，如爱好多选框，写作、阅读、游戏的input标签中都要添加lay-filter=‘aihao’ 然后checkbox(aihao)就是监听的爱好选择
            //值：this.checked = 'true' or 'false'
            var value = this.checked==true ?0:2;
            var id=$(this).attr('data-option');

            $.ajax({
                type: "POST",
                url: "{:url('editUnit')}",
                data: "id="+id+"&field=unit_set_flag"+"&value="+value,
                dataType:"json",
                success: function(res){
                    if (res.code == 1) {
                        // layer.msg(res.msg, {icon: 1});
                    } else {
                        layer.msg(res.msg, {icon: 2,anim: 6});
                    }
                }
            });
        });

    });
    
    
</script>